<template>

  <div class="login-page" ref="vantaRef" >
     <!-- 背景层放最前面，作为背景容器 -->

    <div class="login-container">
      <div class="login-header">
        <h1>交互式数据分析系统</h1>
        <p>请输入您的账号和密码</p>
      </div>

      <div class="login-form" @keyup.enter="handleLogin">
        <div class="input-group">
           <i class="fas fa-user input-icon"></i>
           <input
            type="text"
            v-model="username"
            class="input-text"
            placeholder="请输入用户名"
          >

        </div>

        <div class="input-group">
          <i class="fas fa-lock input-icon"></i>
          <input
            :type="showPassword ? 'text' : 'password'"
            v-model="password"
            class="input-text"
            placeholder="请输入密码"
            @keyup.enter="handleLogin"
          >

          <button
            @click="togglePassword"
            class="toggle-password"
          >
            <!-- <i :class="showPassword ? 'fas fa-eye-slash' : 'fas fa-eye'"></i> -->
          </button>
        </div>

        <div class="forgot-password">
          <a href="#">忘记密码？</a>
        </div>

        <button
          @click="handleLogin"
          class="login-button"
        >
          登录
        </button>

        <div class="register-link">
          <span>还没有账号？</span>
          <a href="#">立即注册</a>
        </div>
      </div>
    </div>
  </div>

</template>

<script>

import * as THREE from 'three'
import BIRDS from 'vanta/src/vanta.birds'
export default {
  name: 'LoginPage',
  data () {
    return {
        vantaEffect: null,
      username: '',
      password: '',
      showPassword: false,

    }
  },
  methods: {
    togglePassword () {
      this.showPassword = !this.showPassword
    },
    handleLogin () {
      if (!this.username || !this.password) {
        alert('请输入用户名和密码')
      } else if (this.username !== 'fan' || this.password !== '123') {
        alert('用户名或密码错误')
      } else {
        this.$router.push(
          {
            path: '/data-analysis'
          })
      }
    }
  },
  mounted() {
    this.vantaEffect = BIRDS({
      el: this.$refs.vantaRef,
      THREE, // ← 这里必须传入 THREE
      mouseControls: true,
      touchControls: true,
      gyroControls: false,
      minHeight: 200.00,
      minWidth: 200.00,
      scale: 1.00,
      scaleMobile: 1.00,
      backgroundColor: 0xffffff,
      color1: 0xff0000,
      color2: 0xd1ff,
      colorMode: "varianceGradient",
      quantity: 5,
      birdSize: 1,
      wingSpan: 30,
      speedLimit: 5,
      separation: 20,
      alignment: 20,
      cohesion: 20
    });
  },
  beforeDestroy() {
    if (this.vantaEffect) this.vantaEffect.destroy()
  }

}
</script>

<style scoped>
.login-page {
  position: relative; /* 背景和登录框都在这个容器中定位 */
  min-height: 98vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

 


.login-container {
  width: 350px;
  padding: 40px;
  border-radius: 20px;
  box-shadow: none; /* 移除阴影 */
  background-color: transparent; /* 设置为完全透明 */
  backdrop-filter: none; /* 移除模糊效果 */
}

.login-header {
  text-align: center;
  margin-bottom: 30px;
}

.login-header h1 {
  font-size: 24px;
  font-weight: bold;
  color: #333;
}

.login-header p {
  font-size: 14px;
  color: #777;
  margin-top: 10px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.input-group {
  position: relative;
}

.input-text {
  width: 90%;
  /* padding: 12px 16px; */
  padding-left: 37px;
  padding-top: 12px;
  padding-bottom: 12px;
  background-color: rgba(248, 248, 248, 0.7);
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  text-align: left;
}

.input-text:focus {
  border-color: #4C89F7;
  outline: none;
  box-shadow: 0 0 5px rgba(76, 137, 247, 0.5);
}

.input-icon {
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  color: #888;
}

.toggle-password {
  position: absolute;
  top: 50%;
  right: 16px;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: #888;
}

.forgot-password {
  text-align: right;
}

.forgot-password a {
  font-size: 12px;
  color: #777;
  text-decoration: none;
}

.forgot-password a:hover {
  color: #4C89F7;
}

.login-button {
  width: 100%;
  padding: 12px 0;
  background-color: #4C89F7;
  color: white;
  font-weight: bold;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.login-button:hover {
  background-color: #366ABF;
}

.register-link {
  text-align: center;
  margin-top: 30px;
  font-size: 14px;
}

.register-link a {
  color: #4C89F7;
  text-decoration: none;
}
.forgot-password a {
  color: #4C89F7;
  text-decoration: none;
}
.register-link a:hover {
  color: #366ABF;
}
.forgot-password a:hover {
  color: #366ABF;
}
</style>
